package com.hst.capacity.infra.persistence.jpa.auth;

import com.alicp.jetcache.anno.Cached;
import com.hst.capacity.domain.model.entity.auth.UserRoleEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface UserRoleRepository extends CrudRepository<UserRoleEntity, String> {

    /**
     * 按用户查找角色
     */
    @Cached(name = "rolesCache::", key = "#userId", expire = 600)
    @Query(value = "select t.roleId from UserRoleEntity t where t.userId = ?1")
    List<String> findByUserId(String userId);
}
